#!/bin/bash

echo "Lumen Installer"
echo "by Abel <zxz054321@163.com>"

sudo chmod -R 777 *

if [ ! -f "/usr/local/bin/composer" ]; then
    echo "Downloading Composer..."
    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
    echo "Composer installed."
    echo ""
fi

if [ ! -f ".env" ]; then
    echo "Would you like to setup .env? Enter the filename to choose one or skip."
    echo "env list:"
    ls .env.*
    echo "Your choice:"
    read input
    echo ""
    if [ -f "$input" ];then
        mv $input .env
        cat .env
        echo ""
        echo "done."
        echo ""
 fi
fi

if [ ! -d "vendor" ]; then
    composer install --no-dev
fi

echo "Require optimization? [y/n]"
read input

if [ "$input" == 'y' ];then
    composer dump-autoload --optimize
fi

echo "Setting permissons..."
sudo chown -R www.www *
sudo chmod -R 777 storage

echo "Installation finished."